package com.tarena.lbs.attach.service.impl;

import com.tarena.lbs.attach.dao.repository.AttachRepository;
import com.tarena.lbs.attach.enums.FileTypeEnum;
import com.tarena.lbs.attach.pojo.dto.AttachDTO;
import com.tarena.lbs.attach.pojo.po.AttachPO;
import com.tarena.lbs.attach.service.AttachService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@Service
public class AttachServiceImpl implements AttachService {
    @Autowired
    private AttachRepository attachRepository;

    @Override
    public AttachDTO insertAttachInfo(MultipartFile file, String fileUuid) {

        AttachDTO attachDTO = new AttachDTO();

        AttachPO attachPO = new AttachPO();
        attachPO.setClientFileName(file.getOriginalFilename());
        attachPO.setContentLength(file.getSize());
        log.debug("文件类型:{}",file.getContentType());
        attachPO.setContentType(FileTypeEnum.PICTURE.getType());
        attachPO.setFileUuid(fileUuid);
        attachPO.setBusinessId(0);
        attachPO.setBusinessType(0);
        //存入数据库
        attachDTO = attachRepository.save(attachPO);
        return attachDTO;
    }
}
